package com.lzcangqiong.design.patterns.factory.simple;

/**
 * 水果园丁
 * Created by luozhen on 2018/6/13.
 */
public class FruitGardener {

    /**
     * 静态工厂
     * @param type 水果类型
     * @return 水果
     * @throws BadFruitException
     */
    public static Fruit factory(String type) throws BadFruitException {
        if ("apple".equals(type)) {
            return new Apple();
        }
        else if ("grape".equals(type)) {
            return new Grape();
        }
        else {
            throw new BadFruitException("类型错误");
        }
    }
}
